package com.bleeth.fx.component;

import com.bleeth.fx.helper.SStyleHelper;
import com.bleeth.fx.layout.FormBuilder;
import com.bleeth.fx.layout.GirdCell;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import lombok.Builder;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@Builder
public class MMessage {

    @Builder.Default
    private String message = "";

    private String type;

    @Builder.Default
    private boolean showClose = false;

    @Builder.Default
    private boolean center = false;


    public Region make() {


        Region icon = MIcon.builder().icon("icon-delete").size(12).build().make();
        Region closeIcon = MIcon.builder().icon("icon-close").size(12).build().make();
        Label messageLabel = new Label(message);

        FormBuilder builder = FormBuilder.form(300D, 40D,Pos.CENTER);
        FormBuilder.RowBuilder rowBuilder;
        if (!center) {
            rowBuilder = builder.addRow(GirdCell.createCell(10D, Pos.CENTER), GirdCell.createCell(1, Pos.CENTER_LEFT, 5D), GirdCell.createCell(30D, Pos.CENTER));
            rowBuilder.addCell(1, icon);
            rowBuilder.addCell(1, messageLabel);
        } else {
            rowBuilder = builder.addRow(GirdCell.createCell(10D, Pos.CENTER), GirdCell.createCell(1, Pos.CENTER, 5D), GirdCell.createCell(30D, Pos.CENTER));
            rowBuilder.addCell(1, icon);
            rowBuilder.addCell(1, messageLabel);
        }

        if (showClose) {
            rowBuilder.addCell(2, closeIcon);
        }
        VBox root = rowBuilder.endRow(false).build();

        SStyleHelper.node(root)
                .addStyle("-fx-background-color", "#c4dbc4")
                .apply();

        return root;
    }


}
